<?php
App::uses('AppController', 'Controller');
/**
 * Evaluaciones Controller
 *
 * @property Evaluacione $Evaluacione
 */
class EvaluacionesController extends AppController {
    public $uses = array(
        'Gestione',
        'Calendario',
        'Ciclo',
        'Padre','User','Paralelo','Profesore', 'Evaluacione');
    public $components = array('Fechasconvert');
    public $layout = 'colegio';

  public function beforeFilter()
    {
        parent::beforeFilter();
        $this->Auth->allow('*');
    }
/**
 * index method
 *
 * @return void
 */
	public function index() {
		$this->Evaluacione->recursive = 0;
		$this->set('evaluaciones', $this->paginate());
	}

/**
 * view method
 *
 * @throws NotFoundException
 * @param string $id
 * @return void
 */
	public function view($id = null) {
		$this->Evaluacione->id = $id;
		if (!$this->Evaluacione->exists()) {
			throw new NotFoundException(__('Invalid evaluacione'));
		}
		$this->set('evaluacione', $this->Evaluacione->read(null, $id));
	}

/**
 * add method
 *
 * @return void
 */
	public function add() {
		if ($this->request->is('post')) {
			$this->Evaluacione->create();
			if ($this->Evaluacione->save($this->request->data)) {
				$this->Session->setFlash(__('The evaluacione has been saved'));
				$this->redirect(array('action' => 'index'));
			} else {
				$this->Session->setFlash(__('The evaluacione could not be saved. Please, try again.'));
			}
		}
        $gestion=date('Y');
		$paralelos = $this->Paralelo->find('all',array(
        'fields'=>array('Paralelo.id','Paralelo.nombre','Paralelo.curso'),
        'conditions'=>array('Paralelo.gestion'=>$gestion),
        'order'=>array('Nivele.orden ASC'),
        'recursive'=>0
        ));
        
         $ciclos = $this->Ciclo->find('all', array(
            'conditions' => array('Ciclo.gestion' => date('Y')),
            'fields' => array('Ciclo.id', 'Ciclo.nombre'),
            'recursive' => -1));
		$profesor=$this->Session->read('Auth.User.profesore_id');
		$this->set(compact('paralelos', 'profesor','ciclos'));
	}

/**
 * edit method
 *
 * @throws NotFoundException
 * @param string $id
 * @return void
 */
	public function edit($id = null) {
		$this->Evaluacione->id = $id;
		if (!$this->Evaluacione->exists()) {
			throw new NotFoundException(__('Invalid evaluacione'));
		}
		if ($this->request->is('post') || $this->request->is('put')) {
			if ($this->Evaluacione->save($this->request->data)) {
				$this->Session->setFlash(__('The evaluacione has been saved'));
				$this->redirect(array('action' => 'index'));
			} else {
				$this->Session->setFlash(__('The evaluacione could not be saved. Please, try again.'));
			}
		} else {
			$this->request->data = $this->Evaluacione->read(null, $id);
		}
		$calendarios = $this->Evaluacione->Calendario->find('list');
		$paralelos = $this->Evaluacione->Paralelo->find('list');
		$profesores = $this->Evaluacione->Profesore->find('list');
		$this->set(compact('calendarios', 'paralelos', 'profesores'));
	}

/**
 * delete method
 *
 * @throws MethodNotAllowedException
 * @throws NotFoundException
 * @param string $id
 * @return void
 */
	public function delete($id = null) {
		if (!$this->request->is('post')) {
			throw new MethodNotAllowedException();
		}
		$this->Evaluacione->id = $id;
		if (!$this->Evaluacione->exists()) {
			throw new NotFoundException(__('Invalid evaluacione'));
		}
		if ($this->Evaluacione->delete()) {
			$this->Session->setFlash(__('Evaluacione deleted'));
			$this->redirect(array('action' => 'index'));
		}
		$this->Session->setFlash(__('Evaluacione was not deleted'));
		$this->redirect(array('action' => 'index'));
	}
}
